package com.sk.cardeal.act.home.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.sk.cardeal.R;
import com.sk.cardeal.act.home.fragment.AlreadyPayFragment;
import com.sk.cardeal.act.home.fragment.FixingFragment;
import com.sk.cardeal.act.home.fragment.WaitPayFragment;
import com.sk.cardeal.act.home.fragment.WaitSendFragment;
import com.sk.cardeal.adapter.MyPagerAdapter;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.entity.OrderRefreshEntity;
import com.sk.cardeal.view.TitleView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sk on 2017/12/15.
 */

public class WorkFormManageActivity extends BaseActivity {

    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.my_table)
    TabLayout myTable;
    @BindView(R.id.my_pager)
    ViewPager myPager;

    WaitSendFragment waitSendFragment;
    FixingFragment fixingFragment;
    WaitPayFragment waitPayFragment;
    AlreadyPayFragment alreadyPayFragment;
    private List<Fragment> fragmentList = new ArrayList<>();

    private int type;

    @Override
    protected int getContentView() {
        return R.layout.activity_work_form_manage;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        type = getIntent().getIntExtra("type",0);
        titleView.setMyCallBack(this);
        initFragments();
    }


    private void initFragments() {

        waitSendFragment = new WaitSendFragment();
        fixingFragment = new FixingFragment();
        waitPayFragment = new WaitPayFragment();
        alreadyPayFragment = new AlreadyPayFragment();

        fragmentList.add(waitSendFragment);
        fragmentList.add(fixingFragment);
        fragmentList.add(waitPayFragment);
        fragmentList.add(alreadyPayFragment);

        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), getResources().getStringArray(R.array.form_array), fragmentList);
        myPager.setAdapter(adapter);
        myTable.setupWithViewPager(myPager);

        switch (type){
            case 2:
                myPager.setCurrentItem(1);
                break;
            case 3:
                myPager.setCurrentItem(2);
                break;
        }

    }


    @Override
    public void clickTitle(int i) {
        super.clickTitle(i);
        switch (i) {
            case 1:
                finish();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == -1) {
            switch (requestCode) {
                case 10:
                    waitSendFragment.doRefresh();
                    fixingFragment.doRefresh();
                    waitPayFragment.doRefresh();
                    alreadyPayFragment.doRefresh();
                    break;
            }
        }

    }
}
